package com.yogee.topseller.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.ProductDetailsActivity;
import com.yogee.topseller.bean.InterlligentFilterBean;
import com.yogee.topseller.utils.GlideUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 智能筛选适配器
 *
 * @auathor ${XiaoJianghong}
 * @date 2017/6/26.
 */

public class IntelligentScreeningBigRvAdapter extends RecyclerView.Adapter<IntelligentScreeningBigRvAdapter.ItemHolder> {

    private Context context;
    private List<InterlligentFilterBean.ProductListBean> beans = new ArrayList<>();

    public IntelligentScreeningBigRvAdapter(Context context) {
        this.context = context;
    }

    public void addData(List<InterlligentFilterBean.ProductListBean> beans) {
        this.beans = beans;
        notifyDataSetChanged();
    }

    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_is_big_img, parent, false);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, int position) {
        final InterlligentFilterBean.ProductListBean bean = beans.get(position);
        GlideUtils.defultImage(context, bean.getImg(), holder.bigImgIv);
        holder.bigImgNameTv.setText(bean.getName());
        if (bean.getLabel().equals("0")) {
            holder.imgMjTv.setVisibility(View.GONE); 
        }
        holder.bigImgQisuMoneyTv.setText(bean.getStartAmount());
        holder.bigImgSyMoneyTv.setText(bean.getExpectReturn());
        holder.bigImgQxDayTv.setText(bean.getInvestmentTerm());
        holder.bigImgYongProTv.setText(bean.getPercent() + "%");
        if (!TextUtils.isEmpty(bean.getPercent())) {
            //33.33
            String[] splitPres = new String[2];
            splitPres = bean.getPercent().split("\\.");
            if (splitPres.length>1){
                holder.bigImgYongPb.setProgress(Integer.parseInt(splitPres[0]));
            }else{
                holder.bigImgYongPb.setProgress(Integer.parseInt(bean.getPercent()));
            }
        }
        holder.bigImgYongBiTv.setText(bean.getCommission());
        if (bean.getDepositDate() == null) {
            holder.bigImgDateTv.setVisibility(View.GONE);
        }
        holder.bigImgDateTv.setText("打款日期：" + bean.getDepositDate());
        if (bean.getCurrentInfo().equals("暂无信息")) {
            holder.bigImgDetailsTv.setVisibility(View.GONE);
        }
        holder.bigImgDetailsTv.setText(bean.getCurrentInfo());

        holder.bigImgLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.startActivity(new Intent(context, ProductDetailsActivity.class).putExtra("id", bean.getId()).putExtra("isFast", "0"));
            }
        });
    }

    @Override
    public int getItemCount() {
        return beans == null ? 0 : beans.size();
    }

    class ItemHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.big_img_ll)
        LinearLayout bigImgLl;
        @BindView(R.id.big_img_iv)
        ImageView bigImgIv;
        @BindView(R.id.big_img_name_tv)
        TextView bigImgNameTv;
        @BindView(R.id.img_mj_tv)
        TextView imgMjTv;
        @BindView(R.id.big_img_qisu_money_tv)
        TextView bigImgQisuMoneyTv;
        @BindView(R.id.big_img_sy_money_tv)
        TextView bigImgSyMoneyTv;
        @BindView(R.id.big_img_qx_day_tv)
        TextView bigImgQxDayTv;
        @BindView(R.id.big_img_yong_bi_tv)
        TextView bigImgYongBiTv;
        @BindView(R.id.big_img_yong_pro_tv)
        TextView bigImgYongProTv;
        @BindView(R.id.big_img_yong_pb)
        ProgressBar bigImgYongPb;
        @BindView(R.id.big_img_date_tv)
        TextView bigImgDateTv;
        @BindView(R.id.big_img_details_tv)
        TextView bigImgDetailsTv;

        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
